{% extends "base.html" %}

{% block title %}设备列表{% end %}

{% block script %}
{% end %}
{% block style %}
<style>
    .color-right {
        background-color: yellowgreen;
        color: white;
    }

    .color-wrong {
        color: red;
    }
</style>
{% end %}

{% block content %}
<div class="container">
    <h3>文件上传</h3>
    <el-upload ref="upload" class="upload-demo" drag action="/uploads" :on-success="onUpload" multiple>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip" slot="tip">暂时只支持apk的上传</div>
    </el-upload>

    <div>
        <template v-for="f in files">
            <el-card class="box-card">
                <img :src="f.iconUrl" alt="icon" style="height: 30px;">
                {{!f.packageName}}
                <em>{{!f.versionName}}</em>
            </el-card>
        </template>
    </div>
</div>
{% end %}

{% block script %}
<script>
    new Vue({
        el: "#app",
        data: {
            title: "hello world",
            files: [{
                iconUrl: "/static/images/android-logo-robot.png",
                packageName: "TODO",
                versionName: "1.1.2"
            }],
        },
        methods: {
            onUpload(resp, file, files) {
                if (!resp.success) {
                    this.$message({
                        message: resp.description,
                        type: "error",
                    })
                    return
                }
                if (!resp.data.iconUrl) {
                    resp.data.iconUrl = "/static/images/android-logo-robot.png"
                }
                this.files.push(resp.data)
                console.log(resp)
                console.log(file)
                console.log(files)
                this.$refs.upload.clearFiles()
            }
        }
    })
</script>
{% end %}